using System;
using System.Collections.Generic;
using Hal;
using Tavis;
using Tavis.Interfaces;

namespace RESTAgent.Hal {
    public class HalLinkExtractor : ILinkExtractor {
		public IEnumerable<Type> SupportedTypes { get { return new[] { typeof(HalDocument) }; } }


        public ILink GetLink(ILinkFactory factory, object content, string relation, string anchor = null) {
            var halContent = (HalDocument) content;
            var halLink = halContent.FindLink(anchor+relation);
            ILink link = factory.CreateLink(halLink.Rel);
			link.Context = anchor != null ? new Uri(anchor, UriKind.RelativeOrAbsolute) : null;

            if (link is Link) {
                Link simpleLink = (Link) link;
                simpleLink.Target = new Uri(halLink.Href, UriKind.RelativeOrAbsolute);
            }
            return link;
        }

        public IEnumerable<ILink> GetLinks(ILinkFactory factory, object content, string relation = null, string anchor = null) {
            throw new NotImplementedException();
        }
    }
}
